<?php

/**
 * [PHPFOX_HEADER]
 */
defined('PHPFOX') or exit('NO DICE!');

/**
 * 
 * 
 * @copyright		[PHPFOX_COPYRIGHT]
 * @author  		Raymond Benc
 * @package 		Phpfox_Service
 * @version 		$Id: process.class.php 2738 2011-07-15 10:28:44Z Miguel_Espinoza $
 */
class Loginsocial_Service_Loginsocial extends Phpfox_Service {

    /**
     * Class constructor
     */
    

    public function __construct() {
        $this->_sTable = Phpfox::getT('loginsocial');
    }

    public function get($sConds) {
        $aRow = $this->database()->select('*')
                ->from($this->_sTable, 'l')
                ->where($sConds)
                ->execute('getRow');
        
        return $aRow;
    }
    
    /**
     * Get user from table user
     * @param mixed $sConds string or array condition
     * @return type
     */
    public function getUser($sConds) {
        $aRow = $this->database()->select('*')
                ->from(Phpfox::getT('user'), 'u')
                ->where($sConds)
                ->execute('getRow');
        
        return $aRow;
    }
    
    public function getListSocial($aListSocial, $iUserId = NULL) {
        if($iUserId === NULL) {
            $iUserId = Phpfox::getUserId();
        }
        
        if(!is_array($aListSocial)) {
            $aListSocial = array($aListSocial);
        }
        
        $sListSocial = implode(',', $aListSocial);
        
        if(!$sListSocial) {
            return FALSE;
        }
        
        $aRows = $this->database()->select('*')
                ->from($this->_sTable, 'l')
                ->where('user_id = ' . $iUserId . ' AND provider IN (' . $aListSocial . ')')
                ->execute('getRows');
        
        if($aRows) {
            return $aRows;
        }
        
        return FALSE;
    }
}

?>